\(\int \cot ^2(c+d x) (a+b \tan (c+d x))^2 (B \tan (c+d x)+C \tan ^2(c+d x)) \, dx\) [12]

   Optimal result
   Rubi [A] (verified)
   Mathematica [C] (verified)
   Maple [A] (verified)
   Fricas [A] (verification not implemented)
   Sympy [B] (verification not implemented)
   Maxima [A] (verification not implemented)
   Giac [A] (verification not implemented)
   Mupad [B] (verification not implemented)

Optimal result

Integrand size = 40, antiderivative size = 70 \[ \int \cot ^2(c+d x) (a+b \tan (c+d x))^2 \left (B \tan (c+d x)+C \tan ^2(c+d x)\right ) \, dx=\left (2 a b B+a^2 C-b^2 C\right ) x-\frac {b (b B+2 a C) \log (\cos (c+d x))}{d}+\frac {a^2 B \log (\sin (c+d x))}{d}+\frac {b^2 C \tan (c+d x)}{d} \]

[Out]

(2*B*a*b+C*a^2-C*b^2)*x-b*(B*b+2*C*a)*ln(cos(d*x+c))/d+a^2*B*ln(sin(d*x+c))/d+b^2*C*tan(d*x+c)/d

Rubi [A] (verified)

Time = 0.22 (sec) , antiderivative size = 70, normalized size of antiderivative = 1.00, number of steps used = 5, number of rules used = 4, \(\frac {\text {number of rules}}{\text {integrand size}}\) = 0.100, Rules used = {3713, 3687, 3705, 3556} \[ \int \cot ^2(c+d x) (a+b \tan (c+d x))^2 \left (B \tan (c+d x)+C \tan ^2(c+d x)\right ) \, dx=x \left (a^2 C+2 a b B-b^2 C\right )+\frac {a^2 B \log (\sin (c+d x))}{d}-\frac {b (2 a C+b B) \log (\cos (c+d x))}{d}+\frac {b^2 C \tan (c+d x)}{d} \]

[In]

Int[Cot[c + d*x]^2*(a + b*Tan[c + d*x])^2*(B*Tan[c + d*x] + C*Tan[c + d*x]^2),x]

[Out]

(2*a*b*B + a^2*C - b^2*C)*x - (b*(b*B + 2*a*C)*Log[Cos[c + d*x]])/d + (a^2*B*Log[Sin[c + d*x]])/d + (b^2*C*Tan
[c + d*x])/d

Rule 3556

Int[tan[(c_.) + (d_.)*(x_)], x_Symbol] :> Simp[-Log[RemoveContent[Cos[c + d*x], x]]/d, x] /; FreeQ[{c, d}, x]

Rule 3687

Int[(((a_.) + (b_.)*tan[(e_.) + (f_.)*(x_)])^2*((A_.) + (B_.)*tan[(e_.) + (f_.)*(x_)]))/((c_.) + (d_.)*tan[(e_
.) + (f_.)*(x_)]), x_Symbol] :> Simp[b^2*B*(Tan[e + f*x]/(d*f)), x] + Dist[1/d, Int[(a^2*A*d - b^2*B*c + (2*a*
A*b + B*(a^2 - b^2))*d*Tan[e + f*x] + (A*b^2*d - b*B*(b*c - 2*a*d))*Tan[e + f*x]^2)/(c + d*Tan[e + f*x]), x],
x] /; FreeQ[{a, b, c, d, e, f, A, B}, x] && NeQ[b*c - a*d, 0] && NeQ[a^2 + b^2, 0] && NeQ[c^2 + d^2, 0]

Rule 3705

Int[((A_) + (B_.)*tan[(e_.) + (f_.)*(x_)] + (C_.)*tan[(e_.) + (f_.)*(x_)]^2)/tan[(e_.) + (f_.)*(x_)], x_Symbol
] :> Simp[B*x, x] + (Dist[A, Int[1/Tan[e + f*x], x], x] + Dist[C, Int[Tan[e + f*x], x], x]) /; FreeQ[{e, f, A,
 B, C}, x] && NeQ[A, C]

Rule 3713

Int[((a_.) + (b_.)*tan[(e_.) + (f_.)*(x_)])^(m_.)*((c_.) + (d_.)*tan[(e_.) + (f_.)*(x_)])^(n_.)*((A_.) + (B_.)
*tan[(e_.) + (f_.)*(x_)] + (C_.)*tan[(e_.) + (f_.)*(x_)]^2), x_Symbol] :> Dist[1/b^2, Int[(a + b*Tan[e + f*x])
^(m + 1)*(c + d*Tan[e + f*x])^n*(b*B - a*C + b*C*Tan[e + f*x]), x], x] /; FreeQ[{a, b, c, d, e, f, A, B, C, m,
 n}, x] && NeQ[b*c - a*d, 0] && EqQ[A*b^2 - a*b*B + a^2*C, 0]

Rubi steps \begin{align*} \text {integral}& = \int \cot (c+d x) (a+b \tan (c+d x))^2 (B+C \tan (c+d x)) \, dx \\ & = \frac {b^2 C \tan (c+d x)}{d}+\int \cot (c+d x) \left (a^2 B+\left (2 a b B+\left (a^2-b^2\right ) C\right ) \tan (c+d x)+\left (b^2 B+2 a b C\right ) \tan ^2(c+d x)\right ) \, dx \\ & = \left (2 a b B+a^2 C-b^2 C\right ) x+\frac {b^2 C \tan (c+d x)}{d}+\left (a^2 B\right ) \int \cot (c+d x) \, dx+(b (b B+2 a C)) \int \tan (c+d x) \, dx \\ & = \left (2 a b B+a^2 C-b^2 C\right ) x-\frac {b (b B+2 a C) \log (\cos (c+d x))}{d}+\frac {a^2 B \log (\sin (c+d x))}{d}+\frac {b^2 C \tan (c+d x)}{d} \\ \end{align*}

Mathematica [C] (verified)

Result contains complex when optimal does not.

Time = 0.31 (sec) , antiderivative size = 91, normalized size of antiderivative = 1.30 \[ \int \cot ^2(c+d x) (a+b \tan (c+d x))^2 \left (B \tan (c+d x)+C \tan ^2(c+d x)\right ) \, dx=-\frac {(a+i b)^2 (B+i C) \log (i-\tan (c+d x))-2 a^2 B \log (\tan (c+d x))+(a-i b)^2 (B-i C) \log (i+\tan (c+d x))-2 b^2 C \tan (c+d x)}{2 d} \]

[In]

Integrate[Cot[c + d*x]^2*(a + b*Tan[c + d*x])^2*(B*Tan[c + d*x] + C*Tan[c + d*x]^2),x]

[Out]

-1/2*((a + I*b)^2*(B + I*C)*Log[I - Tan[c + d*x]] - 2*a^2*B*Log[Tan[c + d*x]] + (a - I*b)^2*(B - I*C)*Log[I +
Tan[c + d*x]] - 2*b^2*C*Tan[c + d*x])/d

Maple [A] (verified)

Time = 0.22 (sec) , antiderivative size = 80, normalized size of antiderivative = 1.14

method result size
parallelrisch \(\frac {\left (-B \,a^{2}+B \,b^{2}+2 C a b \right ) \ln \left (\sec \left (d x +c \right )^{2}\right )+2 B \,a^{2} \ln \left (\tan \left (d x +c \right )\right )+2 C \,b^{2} \tan \left (d x +c \right )+4 d x \left (B a b +\frac {1}{2} C \,a^{2}-\frac {1}{2} C \,b^{2}\right )}{2 d}\) \(80\)
derivativedivides \(-\frac {\frac {\left (B \,a^{2}-B \,b^{2}-2 C a b \right ) \ln \left (\cot \left (d x +c \right )^{2}+1\right )}{2}+\left (2 B a b +C \,a^{2}-C \,b^{2}\right ) \left (\frac {\pi }{2}-\operatorname {arccot}\left (\cot \left (d x +c \right )\right )\right )-\frac {C \,b^{2}}{\cot \left (d x +c \right )}+b \left (B b +2 C a \right ) \ln \left (\cot \left (d x +c \right )\right )}{d}\) \(99\)
default \(-\frac {\frac {\left (B \,a^{2}-B \,b^{2}-2 C a b \right ) \ln \left (\cot \left (d x +c \right )^{2}+1\right )}{2}+\left (2 B a b +C \,a^{2}-C \,b^{2}\right ) \left (\frac {\pi }{2}-\operatorname {arccot}\left (\cot \left (d x +c \right )\right )\right )-\frac {C \,b^{2}}{\cot \left (d x +c \right )}+b \left (B b +2 C a \right ) \ln \left (\cot \left (d x +c \right )\right )}{d}\) \(99\)
norman \(\frac {\left (2 B a b +C \,a^{2}-C \,b^{2}\right ) x \tan \left (d x +c \right )+\frac {C \,b^{2} \tan \left (d x +c \right )^{2}}{d}}{\tan \left (d x +c \right )}+\frac {B \,a^{2} \ln \left (\tan \left (d x +c \right )\right )}{d}-\frac {\left (B \,a^{2}-B \,b^{2}-2 C a b \right ) \ln \left (1+\tan \left (d x +c \right )^{2}\right )}{2 d}\) \(101\)
risch \(i B \,b^{2} x +\frac {4 i C a b c}{d}+\frac {2 i C \,b^{2}}{d \left ({\mathrm e}^{2 i \left (d x +c \right )}+1\right )}+2 B a b x +C \,a^{2} x -C \,b^{2} x +2 i C a b x -\frac {2 i B \,a^{2} c}{d}+\frac {2 i B \,b^{2} c}{d}-i B \,a^{2} x -\frac {\ln \left ({\mathrm e}^{2 i \left (d x +c \right )}+1\right ) B \,b^{2}}{d}-\frac {2 \ln \left ({\mathrm e}^{2 i \left (d x +c \right )}+1\right ) C a b}{d}+\frac {B \,a^{2} \ln \left ({\mathrm e}^{2 i \left (d x +c \right )}-1\right )}{d}\) \(160\)

[In]

int(cot(d*x+c)^2*(a+b*tan(d*x+c))^2*(B*tan(d*x+c)+C*tan(d*x+c)^2),x,method=_RETURNVERBOSE)

[Out]

1/2*((-B*a^2+B*b^2+2*C*a*b)*ln(sec(d*x+c)^2)+2*B*a^2*ln(tan(d*x+c))+2*C*b^2*tan(d*x+c)+4*d*x*(B*a*b+1/2*C*a^2-
1/2*C*b^2))/d

Fricas [A] (verification not implemented)

none

Time = 0.28 (sec) , antiderivative size = 92, normalized size of antiderivative = 1.31 \[ \int \cot ^2(c+d x) (a+b \tan (c+d x))^2 \left (B \tan (c+d x)+C \tan ^2(c+d x)\right ) \, dx=\frac {B a^{2} \log \left (\frac {\tan \left (d x + c\right )^{2}}{\tan \left (d x + c\right )^{2} + 1}\right ) + 2 \, C b^{2} \tan \left (d x + c\right ) + 2 \, {\left (C a^{2} + 2 \, B a b - C b^{2}\right )} d x - {\left (2 \, C a b + B b^{2}\right )} \log \left (\frac {1}{\tan \left (d x + c\right )^{2} + 1}\right )}{2 \, d} \]

[In]

integrate(cot(d*x+c)^2*(a+b*tan(d*x+c))^2*(B*tan(d*x+c)+C*tan(d*x+c)^2),x, algorithm="fricas")

[Out]

1/2*(B*a^2*log(tan(d*x + c)^2/(tan(d*x + c)^2 + 1)) + 2*C*b^2*tan(d*x + c) + 2*(C*a^2 + 2*B*a*b - C*b^2)*d*x -
 (2*C*a*b + B*b^2)*log(1/(tan(d*x + c)^2 + 1)))/d

Sympy [B] (verification not implemented)

Leaf count of result is larger than twice the leaf count of optimal. 136 vs. \(2 (66) = 132\).

Time = 0.75 (sec) , antiderivative size = 136, normalized size of antiderivative = 1.94 \[ \int \cot ^2(c+d x) (a+b \tan (c+d x))^2 \left (B \tan (c+d x)+C \tan ^2(c+d x)\right ) \, dx=\begin {cases} - \frac {B a^{2} \log {\left (\tan ^{2}{\left (c + d x \right )} + 1 \right )}}{2 d} + \frac {B a^{2} \log {\left (\tan {\left (c + d x \right )} \right )}}{d} + 2 B a b x + \frac {B b^{2} \log {\left (\tan ^{2}{\left (c + d x \right )} + 1 \right )}}{2 d} + C a^{2} x + \frac {C a b \log {\left (\tan ^{2}{\left (c + d x \right )} + 1 \right )}}{d} - C b^{2} x + \frac {C b^{2} \tan {\left (c + d x \right )}}{d} & \text {for}\: d \neq 0 \\x \left (a + b \tan {\left (c \right )}\right )^{2} \left (B \tan {\left (c \right )} + C \tan ^{2}{\left (c \right )}\right ) \cot ^{2}{\left (c \right )} & \text {otherwise} \end {cases} \]

[In]

integrate(cot(d*x+c)**2*(a+b*tan(d*x+c))**2*(B*tan(d*x+c)+C*tan(d*x+c)**2),x)

[Out]

Piecewise((-B*a**2*log(tan(c + d*x)**2 + 1)/(2*d) + B*a**2*log(tan(c + d*x))/d + 2*B*a*b*x + B*b**2*log(tan(c
+ d*x)**2 + 1)/(2*d) + C*a**2*x + C*a*b*log(tan(c + d*x)**2 + 1)/d - C*b**2*x + C*b**2*tan(c + d*x)/d, Ne(d, 0
)), (x*(a + b*tan(c))**2*(B*tan(c) + C*tan(c)**2)*cot(c)**2, True))

Maxima [A] (verification not implemented)

none

Time = 0.44 (sec) , antiderivative size = 85, normalized size of antiderivative = 1.21 \[ \int \cot ^2(c+d x) (a+b \tan (c+d x))^2 \left (B \tan (c+d x)+C \tan ^2(c+d x)\right ) \, dx=\frac {2 \, B a^{2} \log \left (\tan \left (d x + c\right )\right ) + 2 \, C b^{2} \tan \left (d x + c\right ) + 2 \, {\left (C a^{2} + 2 \, B a b - C b^{2}\right )} {\left (d x + c\right )} - {\left (B a^{2} - 2 \, C a b - B b^{2}\right )} \log \left (\tan \left (d x + c\right )^{2} + 1\right )}{2 \, d} \]

[In]

integrate(cot(d*x+c)^2*(a+b*tan(d*x+c))^2*(B*tan(d*x+c)+C*tan(d*x+c)^2),x, algorithm="maxima")

[Out]

1/2*(2*B*a^2*log(tan(d*x + c)) + 2*C*b^2*tan(d*x + c) + 2*(C*a^2 + 2*B*a*b - C*b^2)*(d*x + c) - (B*a^2 - 2*C*a
*b - B*b^2)*log(tan(d*x + c)^2 + 1))/d

Giac [A] (verification not implemented)

none

Time = 1.34 (sec) , antiderivative size = 86, normalized size of antiderivative = 1.23 \[ \int \cot ^2(c+d x) (a+b \tan (c+d x))^2 \left (B \tan (c+d x)+C \tan ^2(c+d x)\right ) \, dx=\frac {2 \, B a^{2} \log \left ({\left | \tan \left (d x + c\right ) \right |}\right ) + 2 \, C b^{2} \tan \left (d x + c\right ) + 2 \, {\left (C a^{2} + 2 \, B a b - C b^{2}\right )} {\left (d x + c\right )} - {\left (B a^{2} - 2 \, C a b - B b^{2}\right )} \log \left (\tan \left (d x + c\right )^{2} + 1\right )}{2 \, d} \]

[In]

integrate(cot(d*x+c)^2*(a+b*tan(d*x+c))^2*(B*tan(d*x+c)+C*tan(d*x+c)^2),x, algorithm="giac")

[Out]

1/2*(2*B*a^2*log(abs(tan(d*x + c))) + 2*C*b^2*tan(d*x + c) + 2*(C*a^2 + 2*B*a*b - C*b^2)*(d*x + c) - (B*a^2 -
2*C*a*b - B*b^2)*log(tan(d*x + c)^2 + 1))/d

Mupad [B] (verification not implemented)

Time = 8.59 (sec) , antiderivative size = 90, normalized size of antiderivative = 1.29 \[ \int \cot ^2(c+d x) (a+b \tan (c+d x))^2 \left (B \tan (c+d x)+C \tan ^2(c+d x)\right ) \, dx=\frac {B\,a^2\,\ln \left (\mathrm {tan}\left (c+d\,x\right )\right )}{d}+\frac {\ln \left (\mathrm {tan}\left (c+d\,x\right )+1{}\mathrm {i}\right )\,\left (B-C\,1{}\mathrm {i}\right )\,{\left (b+a\,1{}\mathrm {i}\right )}^2}{2\,d}+\frac {C\,b^2\,\mathrm {tan}\left (c+d\,x\right )}{d}+\frac {\ln \left (\mathrm {tan}\left (c+d\,x\right )-\mathrm {i}\right )\,\left (B+C\,1{}\mathrm {i}\right )\,{\left (-b+a\,1{}\mathrm {i}\right )}^2}{2\,d} \]

[In]

int(cot(c + d*x)^2*(B*tan(c + d*x) + C*tan(c + d*x)^2)*(a + b*tan(c + d*x))^2,x)

[Out]

(B*a^2*log(tan(c + d*x)))/d + (log(tan(c + d*x) + 1i)*(B - C*1i)*(a*1i + b)^2)/(2*d) + (C*b^2*tan(c + d*x))/d
+ (log(tan(c + d*x) - 1i)*(B + C*1i)*(a*1i - b)^2)/(2*d)